home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Utilities Professional 1-1500
/
Utilities Professional 1-1500 (1994)(WPD)[!].iso
/
07511000
/
var0888.dms
/
var0888.adf
/
WoManD
/
man
/
C_Library
/
fscanf
< prev
next >
Wrap
Text File
|
1992-09-19
|
4KB
|
109 lines
FSCANF(1) C LIBRARY FUNCTIONS FSCANF(1)
NAME
fscanf, scanf, sscanf - formatted input functions.
SYNOPSIS
int fscanf(const char *cntrl_string, ...);
int scanf(FILE *fp, const char *cntrl_string, ...);
int sscanf(char *s, const char *cntrl_string, ...);
INCLUDE FILE
stdio.h
DESCRIPTION
fscanf() reads text from the file associated with fp, converts the
characters according to the conversion specification in
cntrl_string, placing the values in memory at the addresses
specified by the other arguments. fscanf() returns the number of
conversion accomplished, or EOF if an end-of-file is encountered
or if no conversion have occurred.
scanf() is equivalent to fscanf(stdin, , ...).
sscanf() is equivalent to scanf(), except that it reads from the string
s instead of a file.
Each of these functions convert formats, and read their arguments
under control of the format string. The format is a character string
which contains blanks or tabs which are ignored, Ordinary character
(excluding %) which are expected to match the next non blank character
of the input stream, and conversion specifications, each of which causes
conversion of a string into variable pointed to by the corresponding
argument.
Each conversion specification is of the form
%*n(l|L|h)t
where all the parameters are optional apart from the type t.
- * : if present, it means that the conversion should be performed, but
the result should not be stored. Their should be no argument
pointer for that conversion.
- n : an integer that specifies the maximal scan width.
- l/L/h : indicates that the pointer refers to a long or short type of
object. For integers object (d,i,o,u,x,X), l means that the
object must be stored in a long integer. For float objects
(e,E,g,G,f), it means that the object must be stored in a
double. L can precede e,E,g,G or f to indicated that the
converted value must be stored in a long double.
- t : c : any char, converted to (arg: char *).
d,i : optionally signed decimal integer (arg: int *).
u : optionally signed decimal integer (arg: unsigned int *).
o : optionally signed octal integer (arg: unsigned int *).
x,X : optionally signed hexadecimal integer (arg: unsigned int *).
s : a sequence of non white space characters. (arg: char *).
A string ends with a BLANK SPACE or '\n'.
- f,e,E,g,G : optionally signed floating point number. (arg :float *).
p : what is produced by %p in printf() (usually an unsigned
hexadecimal number) (arg : void * *).
n : the corresponding argument is a pointer to an integer
into which the number of character read so far is put.
% : %% prints the '%' sign.
[...] : Matches the longest non-empty string of input character
that only contains characters listed inside the brackets.
(arg : char *).
[^..] : Matches the longest non-empty string of input character
that contains any characters but those listed inside the
brackets. (arg : char *).
EXAMPLES
- if a file containing
4 5 , Disregard_this, x This_is_a_string
is read by the following call to fscanf(),
int i;
short j;
char *str,Buff[125];
FILE *fp;
/* open the file */
fscanf(fp,"%d %hd , %*s %% %c %4s %s ",&i,&j,str,Buff);
then, the variable will contain the following:
i => 4, j => 5, str => This, Buff => _is_a_string .
- If the following program
main()
{ char mantissa[20],exponent[20];
scanf("%[^Ee]%[1234567890]",mantissa,exponent);
printf("%se%s\n",mantissa,exponent);
}
is given 123e4 in input, it will print 123E4 on stdout.
SEE ALSO
open(), close(), getc(), printf().